package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.entity.Department;
import com.HospitalOutpatient.entity.Medication;
import com.HospitalOutpatient.service.DepartmentService;
import com.HospitalOutpatient.vo.DepartmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @LoginToken
    @GetMapping("/getAllDepartment")
    public Result getAllDepartment(){
        List<Department> departmentList = departmentService.getAllDepartment();
        return new Result(Code.GET_OK,departmentList,"科室信息");
    }
    @LoginToken
    @PostMapping("/addDepartment")
    public Result addDepartment(@RequestBody Department department){
        boolean b = departmentService.addDepartment(department);
        if(b == false){
            return new Result(Code.SAVE_ERR,null,"添加科室失败");
        }
        return new Result(Code.SAVE_OK,null,"添加科室成功");
    }
    @LoginToken
    @PostMapping("/editDepartment")
    public Result editDepartment(@RequestBody Department department){
        boolean b = departmentService.editDepartment(department);
        if(b == false){
            return new Result(Code.UPDATE_ERR,null,"修改科室失败");
        }
        return new Result(Code.UPDATE_OK,null,"修改科室成功");
    }
    @LoginToken
    @GetMapping("/getChooseDepartmentList")
    public Result getChooseDepartmentList(){
        List<DepartmentVo> chooseDepartmentList = departmentService.getChooseDepartmentList();
        return new Result(Code.GET_OK,chooseDepartmentList,"可选科室信息");
    }
}
